package com.itheima.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class SMSUtils {

    public   final   static String  ACCESSKEYID = "LTAIA2KE6onERO5f";  //  用户 管理  id
    public   final   static String  SECRET = "raxTWs3twt1k9ESJrS2kUyrDUMFoGx";
    public   final   static String  SMSCODE = "SMS_192541298";  //  短信模板 code
    public   final   static String  SINATURENAME = "传智健康黑马唐"; // 短信签名名称

    public  static  CommonResponse  send(String telephone ,String code){
//        18963139422
            DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou",
                    ACCESSKEYID, SECRET);
            IAcsClient client = new DefaultAcsClient(profile);
            CommonRequest request = new CommonRequest();
            request.setSysMethod(MethodType.POST);
            request.setSysDomain("dysmsapi.aliyuncs.com");
            request.setSysVersion("2017-05-25");
            request.setSysAction("SendSms");
            request.putQueryParameter("RegionId", "cn-hangzhou");
            request.putQueryParameter("PhoneNumbers", telephone);
            request.putQueryParameter("SignName", SINATURENAME);
            request.putQueryParameter("TemplateCode", SMSCODE);
            request.putQueryParameter("TemplateParam", "{\"code\":\""+code+"\"}");
            try {
                CommonResponse response = client.getCommonResponse(request);
                System.out.println(response.getData());
                return  response;
            } catch (Exception e) {
                e.printStackTrace();
                throw  new RuntimeException(e);
            }
        }


}
